package com.keyidea.jfxui.portal.view.server.test;

import com.keyidea.jfxui.core.config.YamlConfig;
import com.keyidea.jfxui.core.config.context.SpringContextHelper;
import com.keyidea.jfxui.core.util.YamlUtil;
import de.saxsys.mvvmfx.SceneLifecycle;
import de.saxsys.mvvmfx.ViewModel;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import lombok.Data;

@Data
public class ComponentTestViewModel implements ViewModel, SceneLifecycle {

    private StringProperty redisIp = new SimpleStringProperty();
    private SimpleIntegerProperty redisPort = new SimpleIntegerProperty();
    private StringProperty redisPassword = new SimpleStringProperty();
    private StringProperty redisMessage = new SimpleStringProperty();
    private StringProperty redisKey = new SimpleStringProperty();

    private StringProperty udpLocalIp = new SimpleStringProperty();
    private IntegerProperty udpLocalPort = new SimpleIntegerProperty();
    private StringProperty udpRemoteIp = new SimpleStringProperty();
    private IntegerProperty udpRemotePort = new SimpleIntegerProperty();
    private StringProperty udpMessage = new SimpleStringProperty();

    private StringProperty redisLog = new SimpleStringProperty();

    public ComponentTestViewModel() {
        initData();
    }

    private void initData() {
        YamlConfig yamlConfig = SpringContextHelper.getBean(YamlConfig.class);

        redisIp.setValue(yamlConfig.getRedisHost());
        redisPort.setValue(yamlConfig.getRedisPort());
        redisPassword.setValue(yamlConfig.getRedisPassword());

        udpLocalIp.setValue(yamlConfig.getLocalIp());
        udpLocalPort.setValue(yamlConfig.getLocalPort());
        udpRemoteIp.setValue(yamlConfig.getRemoteIp());
        udpRemotePort.setValue(yamlConfig.getRemotePort());
        redisLog.setValue("");
    }

    @Override
    public void onViewAdded() {
        System.out.println("onViewAdded+++++++++++++++++++++");
    }

    @Override
    public void onViewRemoved() {
        System.out.println("onViewRemoved-------------------");
    }
}
